package servlet;

import dao.ProductDaoImpl;
import pojo.Product;
import sevice.ProductService;
import sevice.ProductServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author 郝雷蒙
 * @Description
 * @date 2020/11/26 9:49
 */

public class GetAllProducts extends HttpServlet {
    private ProductService productService = new ProductServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html");



        String aorder = req.getParameter("order");

        String order = (aorder==null)?"a" :aorder;


        List<Product> products = productService.getAllproducts(order);
        products.get(0).setAllSumPrice(new ProductDaoImpl().selectAllSumPrice().getAllSumPrice());


        req.setAttribute("products",products);

        req.getRequestDispatcher("all_product.jsp").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       doGet(req,resp);
    }
}
